#include "teachinterface.h"
#include "ui_teachinterface.h"
#include<QDebug>
#include<QMessageBox>
#include<QMouseEvent>
#include<QFileDialog>
#include<QPainter>
#include<QSqlQuery>
#include<QSqlError>
#include<QBuffer>
#include<QBitArray>
#include<QTextEdit>
teachInterface::teachInterface(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::teachInterface)
{
    ui->setupUi(this);
//    db=QSqlDatabase::addDatabase("QMYSQL");
//    db.setHostName("192.168.111.128");
//    db.setUserName("root");
//    db.setPassword("123456");
//    db.setDatabaseName("teacher");
//    db.setPort(3306);
//    if(!db.open())
//    {
//        qDebug()<<db.lastError()<<endl;
//        return;
//    }
    connect(ui->display,&QPushButton::clicked,this,&teachInterface::Display);
    //connect(ui->delete_2,&QPushButton::clicked,ui->textEdit,SLOT(clear()));


}

void teachInterface::setStudentName(const QString &name)
{
    studentName =name;
}

teachInterface::~teachInterface()
{
    delete ui;
}

void teachInterface::Display()
{
    QSqlQuery query;//语句执行对象


     if(query.exec("select*from student_list where Name=;"))
     {

         if(query.next())
         {
         ui->name_edit->setText(query.value("Name").toString());
         ui->name_edit->setReadOnly(true);
         ui->score_edit->setText(query.value("Sex").toString());
         ui->score_edit->setReadOnly(true);
         ui->teacher_edit->setText(query.value("teacher").toString());
         ui->teacher_edit->setReadOnly(true);
         //ui->textEdit->setText(query.value("remarks").toString());
          }

     }

    if(query.exec("select student_list from interface where Name=;"))
    {

        if(query.next())
        {
            QByteArray imageInfo=query.value("image").toByteArray();//取出图片数据
            QPixmap m;
            m.loadFromData(imageInfo);
            QPixmap chopped=m.scaled(ui->STU_IMAGE->width(),ui->STU_IMAGE->height(),Qt::KeepAspectRatioByExpanding);
            QRect chopRect((chopped.width()-ui->STU_IMAGE->width())/2,0,ui->STU_IMAGE->width(),ui->STU_IMAGE->height());
            ui->STU_IMAGE->setPixmap(chopped.copy(chopRect));
        }
    }

}


